package com.skyline.wizard.mapper;

import org.apache.lucene.document.Document;

import com.skyline.wo.model.Article;

public class ArticleObjMapper implements ObjMapper<Article> {

	private static final String COLUMN_ID = "id";
	private static final String COLUMN_DIGEST = "digest";
	private static final String COLUMN_TITLE = "title";
	private static final String COLUMN_OWNER_ID = "ownerId";
	private static final String COLUMN_OWNER_NICKNAME = "ownerNickname";
	private static final String COLUMN_OWNER_PORTRAIT = "ownerPortrait";
	private static final String COLUMN_CATEGORY_ID = "categoryId";
	private static final String COLUMN_CATEGORY_NAME = "categoryName";

	private static ArticleObjMapper mapper = new ArticleObjMapper();

	public static ArticleObjMapper getMapper() {
		return mapper;
	}

	public Article map(Document d) {
		Article a = new Article();
		a.setId(Long.valueOf(d.get(COLUMN_ID)));
		a.setDigest(d.get(COLUMN_DIGEST));
		a.setTitle(d.get(COLUMN_TITLE));
		a.setOwnerId(Long.valueOf(d.get(COLUMN_OWNER_ID)));
		a.setOwnerNickname(d.get(COLUMN_OWNER_NICKNAME));
		a.setOwnerPortrait(d.get(COLUMN_OWNER_PORTRAIT));
		a.setCategoryId(Long.valueOf(d.get(COLUMN_CATEGORY_ID)));
		a.setCategoryName(d.get(COLUMN_CATEGORY_NAME));
		return a;
	}
}
